<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
</style>
<script type="text/javascript">
    var tempStoageTaskDataGrid;
    $(function() {
        tempStoageTaskDataGrid = $('#tempStoageTaskDataGrid').datagrid({
            url : '${path}/process/tempStoageTask/dataGrid?userid=<shiro:principal property = "id"/>',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            pageSize : 15,
            pageList : [ 15, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            columns : [ [
                {
                    width : '200',
                    title : '标题',
                    field : 'title'
                },
                {
                    width : '100',
                    title : '流程类型',
                    field : 'businessType'
                },
                {
                    width : '100',
                    title : '创建时间',
                    field : 'createTime'
                    ,formatter : function(value, row, index) {
                        return datetime2Str(value)
                    }
                }


            ]],
            frozenColumns : [ [{
                field : 'action',
                title : '操作',
                width : 370,
                formatter : function(value, row, index) {
                    var str = '';
                    str += $.formatString('<a href="javascript:void(0)" class="tempStoageTask-easyui-linkbutton-submit" data-options="plain:true,iconCls:\'fi-check icon-blue\'" onclick="submitTempStoageTask(\'{0}\',\'{1}\',\'{2}\');" ></a>', row.id,row.businessKey,row.objId);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="tempStoageTask-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-green\'" onclick="editTempStoageTask(\'{0}\',\'{1}\',\'{2}\');" ></a>', row.id,row.businessKey,row.objId);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="tempStoageTask-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-trash icon-red\'" onclick="delTempStoageTask(\'{0}\');" ></a>', row.id);
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.tempStoageTask-easyui-linkbutton-submit').linkbutton({text:'提交'});
                $('.tempStoageTask-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.tempStoageTask-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
        });
    });

    /**提交暂存
     * [submitTempStoageTask description]
     * @param  {[type]} id [description]
     * @return {[type]}    [description]
     */
    function submitTempStoageTask(id,businessKey,objId){
       $.ajax({
            url:'${path}/example/'+businessKey+'/submitProcessInstance',
            data:{"id":objId},
            dataType:'json',
            type:'post',
            success:function(data){
                if(data.success){
                    showMsg(data.msg);
                    $.post('${path}/process/tempStoageTask/deleteById', {id: id}, function(data, textStatus, xhr) {
                        if(data.success){
                             tempStoageTaskDataGrid.datagrid('reload');
                        }
                    },'json');
                }else{
                    parent.$.messager.alert('错误',data.msg,'error');
                }
            }
        })
    }


    /**
     * 编辑暂存内容
     * @param  {[type]} id          [description]
     * @param  {[type]} businessKey [description]
     * @param  {[type]} objId       [description]
     * @return {[type]}             [description]
     */
    function editTempStoageTask(id,businessKey,objId){
        parent.$.modalDialog({
            title : '编辑',
            width : '80%',
            height : '80%',
            href : '${path}/example/'+businessKey+'/editPage?id=' + objId,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid =tempStoageTaskDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#'+businessKey+'EditForm');
                    f.submit();
                }
            } ]
        });
    }
    /**
     * 
     * [delTempStoageTask 删除暂存任务]
     * @param  {[type]} id [description]
     * @return {[type]}    [description]
     */
    function delTempStoageTask(id){
        if (id== undefined) {//点击右键菜单才会触发这个
            var rows = tempStoageTaskDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            tempStoageTaskDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除吗？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path}/process/tempStoageTask/del?id='+id, {}
                , function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        tempStoageTaskDataGrid.datagrid('reload');
                    }else{
                        parent.$.messager.alert('提示', result.msg, 'info');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:true,title:''">
        <table id="tempStoageTaskDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
